#include "pix5core.h"

Job::Job()
{
	_jobState = JS_NONE;
	_jobSelfDestruct = false;
}

Job::~Job()
{
}


JobState Job::getJobState()
{
	return _jobState;
}


void Job::setJobState(JobState js)
{
	_jobState = js;
}

void Job::setJobSelfDestruct(bool sd)
{
	_jobSelfDestruct = sd;
}

bool Job::getJobSelfDestruct()
{
	return _jobSelfDestruct;
}



/////////////////////////////////////////////////////////////////////////////



JobRunner::JobRunner()
{
}

JobRunner::~JobRunner()
{
}

void JobRunner::onThreadStart()
{
	for(;;)
	{
		Job* job;

		try
		{
			job = ThreadMan::popJob();
		}
		catch(Error)
		{
			return;
		}

		try
		{
			job->setJobState(JS_RUNNING);
			job->onJobStart();
			job->setJobState(JS_DONE);
		}
		catch(Error)
		{
			job->setJobState(JS_ERROR);
		}

		try
		{
			if(job->getJobSelfDestruct())
				delete job;
		}
		catch(Error)
		{
			ASSERT(false,"Internal Error")
		}

	}
}



